home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Libris Britannia 4
/
science library(b).zip
/
science library(b)
/
PROGRAMM
/
DB_CLIPP
/
0411.ZIP
/
ANSWER.C
< prev
next >
Wrap
Text File
|
1985-09-18
|
2KB
|
86 lines
#include "stdio.h"
main(argc,argv)
int argc;
char *argv[];
{
int c,
i,
parmlen,
loop;
char bs,
cr,
blanklin[80];
if (argc == 1)
{
exit(0);
}
if (argv[1][0] == '#')
{
puts("\n");
puts("Author : Peter Townsend\n");
puts("Date : 18Sep85\n");
puts("Time : 08:22\n");
puts("Version: 1.0\n");
exit(0);
}
if (argv[1][0] == '?')
{
puts("\n");
puts("This program reads 1 character from the standard input device\n");
puts("and compares it to a list of characters passed in as a\n");
puts("parameter. If a match is found - case insensitive - then the\n");
puts("position of the match in the parameter string is returned as\n");
puts("the exit code. If no match is found, the character is ignored.\n");
puts("\n");
puts("NB When testing for an errorlevel in a DOS batch file, test\n");
puts(" for the lowest errorlevel first, as an errorlevel of n is\n");
puts(" also equal to n-1 ... n-n where n >= 1.\n");
puts("\n");
puts("Syntax: ANSWER [parm]\n");
puts("\n");
puts("Defaults: Exit code = 0 on no parameter string\n");
puts("\n");
puts("Example: ANSWER yn\n");
puts(" with a read of 'y' or 'Y' returns code 1\n");
puts(" \" \" \" \" 'n' \" 'N' \" \" 2\n");
puts("\n");
exit(0);
}
for(i=0;i<79;i++)
{
blanklin[i] = 0x20;
}
blanklin[79] = '\0';
parmlen = strlen(argv[1]);
bs = 0x8;
cr = 0xd;
loop = 1;
puts("\n");
printf("%c%s%cSelect from: %s ",cr,blanklin,cr,argv[1]);
while (loop == 1)
{
c = getchar();
if ((c == cr) | (c == 0) | (c == 9) | (c == 8))
{
printf("%c%s%cSelect from: %s ",cr,blanklin,cr,argv[1]);
if (c == 0)
{
c = getchar();
printf("%c %c",bs,bs);
}
}
else
{
for (i=0;i<parmlen;i++)
{
if (toupper(c) == toupper(argv[1][i]))
{
puts("\n");
exit(i+1);
}
}
printf("%c %c",bs,bs);
}
}
}